﻿@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService
@inject IJSRuntime JS
@inject IEventService _eventService

<MExpansionPanels>
    <MExpansionPanel @key="0">
        <MExpansionPanelHeader>
            <div class="" style=" display: flex; align-items: center; ">
                <img src="@Model.GroupImage" style="height:50px;width:50px;border-radius:50%;" />
                <div class="ms-3" style="font-size: x-large; font-weight: bold;">@Model.GroupName</div>
            </div>
        </MExpansionPanelHeader>
        <MExpansionPanelContent>
            <div>
                @if (string.IsNullOrWhiteSpace(Model.BriefIntroduction) == false)
                {
                    <div class="mb-2">@Model.BriefIntroduction</div>

                }
                <div style=" display: flex; flex-direction: row; ">
                    @if (string.IsNullOrWhiteSpace(Model.Outlink) == false)
                    {
                        <MButton Rounded Color="primary" OnClick="OnClickWeibo" Class="me-3">
                            <MIcon Left>@((Model.Outlink.Contains("weibo") ? IconType.Weibo : IconType.Link).ToIconString())</MIcon>
                           @((Model.Outlink.Contains("weibo") ? "访问微博主页" : "访问社交媒体主页")) 
                        </MButton>
                    }

                    <MButton Rounded Color="primary" OnClick="OnClickMainPage">
                        <MIcon Left>@IconType.Entry.ToIconString()</MIcon>
                        @(Model.GroupId>0?"查看词条":"查看个人空间")
                    </MButton>

                </div>
            </div>
        </MExpansionPanelContent>
    </MExpansionPanel>

    @foreach (var item in Model.Articles)
    {
        <MExpansionPanel @key="@(Model.Articles.IndexOf(item)+1)">
            <MExpansionPanelHeader>
                @(item.DisplayName+" - "+item.LastEditTime.ToTimeFromNowString())
            </MExpansionPanelHeader>
            <MExpansionPanelContent Class="pa-0">
                <CnGalWebSite.Shared.MasaComponent.Shared.Cards.Search.ArticleInforViewTip Model="item" Outline HideTitle />
            </MExpansionPanelContent>
        </MExpansionPanel>
    }
</MExpansionPanels>

@code {
    [Parameter]
    public NewsSummaryAloneViewModel Model { get; set; }

    #region 新建标签页
    public async void OpenNewPage(string url)
    {
        await _eventService.OpenNewPage( url);
    }
    #endregion

    public void OnClickWeibo()
    {
        OpenNewPage(Model.Outlink);
        
    }

    public void OnClickMainPage()
    {
        NavigationManager.NavigateTo(Model.GroupId > 0 ? ("entries/index/" + Model.GroupId) : ("space/index/" + Model.UserId));
        
    }
}
